#include "Server.h"

// 接收线程
void * pthread_recv(void * arg)
{
    int sockfd = *(int *)arg;
    //接收
    char buf[1024];
    memset(buf,0,sizeof(buf));
<<<<<<< HEAD
    //接收字符数量
    int byte_recv = 0;
    //返回值变量
    static int return_val = 0;
    while(1)
    {
        byte_recv = recv(sockfd,buf,sizeof(buf),0);
        // if(0 == strcmp(buf,"quit"))
        // {
        //     break;
        // }
        //错误判断
        if(-1 == byte_recv)
        {
            ERRLOG("接受错误\n");
            return NULL;
        }
        else if(0 == byte_recv)
        {
            printf("读取结束\n");
            //返回1 代表TCP连接结束
            return_val = 1;
            return (void*)&return_val;
        }
        printf("接收到的信息 %s \n",buf);
        memset(buf,0,sizeof(buf));
    }

=======
    while(1)
    {
        recv(sockfd,buf,sizeof(buf),0);
        if(0 == strcmp(buf,"quit"))
        {
            break;
        }
        printf("接收到的信息 %s \n",buf);
    }
    //关闭连接
    //tcp_server_close();
>>>>>>> 2cc30ecdf3e882fb43792ee2711ac0e0661a1afe
}

// 发送线程
void * pthread_send(void * arg)
{
    int sockfd = *(int *)arg;
<<<<<<< HEAD
    char buf[1024];
    memset(buf,0,sizeof(buf));
    //收发
    while(1)
    {
        //从键盘获取字符
        printf("发送：");
        scanf("%s",buf);
        if(0 == strlen(buf))
        {
            printf("未输入数据，请重新输入\n");
            continue;
        }
        //发送一段信息
        if(-1 == send(sockfd,buf,strlen(buf) , 0))
        {
            ERRLOG("写入错误\n");
            return NULL;
        }
       memset(buf,0,sizeof(buf));
    }
=======
    //收发
    //发送一段信息
        send(sockfd,"你好，我是陈宇\n",strlen("你好，我是陈宇\n") , 0);
    //关闭连接
    //tcp_server_close();
>>>>>>> 2cc30ecdf3e882fb43792ee2711ac0e0661a1afe
}
